#ifndef SCENE_H
#define SCENE_H

#include <QtGui>

#include <defs/export.h>
#include <defs/global.h>

#include "entity.h"

namespace Opl{ namespace Gui {

        class ProxyWidget : public QGraphicsProxyWidget
        {
        public:
            ProxyWidget(QGraphicsItem *parent = 0)
                : QGraphicsProxyWidget(parent)
            {
            }

        protected:
            QVariant itemChange(GraphicsItemChange change, const QVariant & value)
            {
                // we want the position of proxy widgets to stay at (0, 0)
                // so ignore the position changes from the native QWidget
                if (change == ItemPositionChange)
                    return QPointF();
                else
                    return QGraphicsProxyWidget::itemChange(change, value);
            }
        };

        class Light;
        class Entity;
        O_PRIVATE_DECLARE(Scene);

        class EXPORTED Scene : public QGraphicsScene {
            Q_OBJECT
        public:
            Scene(int width, int height, int maxTextureSize);
            ~Scene();
            virtual void drawBackground(QPainter *painter, const QRectF &rect);

        public slots:
            void setShader(int index);
            void setTexture(int index);
            void toggleDynamicCubemap(int state);
            void setColorParameter(const QString &name, QRgb color);
            void setFloatParameter(const QString &name, float value);
            void newItem();
        protected:
            void render(const QMatrix4x4 &view);
            void setStates();
            void setLights();
            void defaultStates();
           // void renderCubemaps();

            virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
            virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
            virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
            virtual void wheelEvent(QGraphicsSceneWheelEvent * event);
        private:
            void initGL();
            QPointF pixelPosToViewPos(const QPointF& p);
            O_PRIVATE_DECLARE_MEMBER(Scene);
        };
    };};

#endif // SCENE_H

